package com.gdones.bootserver.bus.staff.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdones.bootserver.bus.staff.dto.Staff;
import com.gdones.bootserver.bus.staff.mapper.StaffMapper;
import com.gdones.bootserver.bus.staff.service.IStaffService;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyPager;
import com.gdones.common.core.dto.MyResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-04-04
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements IStaffService {

    @Override
    public MyPager<Staff> pages(Staff dto, MyPageBand pager) {

        StaffMapper staffMapper = getBaseMapper();

        IPage<Staff> pages = staffMapper.myPage(PageDTO.of(pager.getPage(),pager.getSize()),dto);

        // 根据分页的结果封装返回数据
        MyPager<Staff> pagers = new MyPager<>();
        pagers.setTotal(pages.getTotal());
        pagers.setPage(pager.getPage());
        pagers.setPageSize(pager.getSize());
        pagers.setRows(pages.getRecords());

        return pagers;
    }

    @Override
    public List<Staff> list(Staff dto) {

        StaffMapper staffMapper = getBaseMapper();

        List<Staff> list =  staffMapper.list(dto);

        return list;
    }

    @Override
    public MyResult granteStaffAccount(Staff dto) {

        MyResult result = new MyResult();

        boolean b = this.updateById(dto);

        if(b){
            result.setMsg("授权成功！");
        }else{
            result.setMsg("授权出错！");
            result.setCode("9999");
        }

        return result;
    }


}
